function drawMatches(im1,rows1,cols1,im2,rows2,cols2,nearest_idx,nearest_dist,threshold,H)
%DRAWMATCHES 
% nearest_idx, nearest_dist are returned by the matching function
% threshold : draw all matches for which the distance (or ratio) in nearest_dist is below the threshold
% H: 3x3 Homography to transform from im1 to im2 
    transformedCoords = H * [cols1'-1;rows1'-1;ones(1,length(cols1))];
    transformedCoords = transformedCoords./repmat(transformedCoords(3,:),3,1);
    diff = transformedCoords(1:2,:) - [cols2(nearest_idx)'-1;rows2(nearest_idx)'-1];
    dist = sqrt(sum(diff.^2))';
    inds_positive_matches = find(nearest_dist<threshold & dist<4);
    inds_negative_matches = find(nearest_dist<threshold & dist>=4);
    imagesc(cat(2,im1,im2)); %assuming images of same height
    hold on;
    line([cols1(inds_positive_matches)';size(im1,2)+cols2(nearest_idx(inds_positive_matches))'],...
            [rows1(inds_positive_matches)';rows2(nearest_idx(inds_positive_matches))'],'Color','g');
    line([cols1(inds_negative_matches)';size(im1,2)+cols2(nearest_idx(inds_negative_matches))'],...
            [rows1(inds_negative_matches)';rows2(nearest_idx(inds_negative_matches))'],'Color','r');
end
