You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: peak_det_matched_filter_robust.m
    path of file: ./repos/OSET/matlab/tools/ecg
    
    the code of the file until where you have to start completion: function [peaks, r] = peak_det_matched_filter_robust(ref, fs, h, fmax, varargin)
% peak_det_matched_filter_robust: R-peak detector based on a matched filter
%
% Syntax: [peaks, r] = peak_det_matched_filter_robust(ref, fs, h, fmax, itr)
%
% Inputs:
%   ref:    Vector of input data.
%   fs:     Sampling rate.
%   h:      Template waveform.
%   fmax:   Maximum expected frequency of the R-peaks.
%   itr:    Number of iterations to run the post-matched filter peak detector (Default: 1, run peak detector only once)
%
% Outputs:

    
function [peaks, r] = peak_det_matched_filter_robust(ref, fs, h, fmax, varargin)
% peak_det_matched_filter_robust: R-peak detector based on a matched filter
%
% Syntax: [peaks, r] = peak_det_matched_filter_robust(ref, fs, h, fmax, itr)
%
% Inputs:
%   ref:    Vector of input data.
%   fs:     Sampling rate.
%   h:      Template waveform.
%   fmax:   Maximum expected frequency of the R-peaks.
%   itr:    Number of iterations to run the post-matched filter peak detector (Default: 1, run peak detector only once)
%
% Outputs:
%   peaks:  Vector of R-peak impulse train.
%   r:      Filtered output after matched filtering.
%
%   Revision History:
%       2008: First release
%       2023: Renamed from deprecated version PeakDetection4()
%
%   Reza Sameni, 2006-2023
%   The Open-Source Electrophysiological Toolbox
%   https://github.com/alphanumericslab/OSET

% Parse the vararg input
if isempty(varargin)
    itr = 1; % Default value if itr
else
    itr = varargin{1};
end