function H = ransac(img_Loc1, img_Loc2, N, inlier_Thresh)
% imgLoc1 - N x 2 locations of N points
% imgLoc2 - N x 2 locations of N points
%fprintf(N,inlier_Thresh, inlier_Count_Thresh);

    max = 0;
    [n, m] = size(img_Loc1);
    pt_Count = size(img_Loc1, 1);
    
    assert(size(img_Loc2, 1) == pt_Count);
    
    homog_ImgLoc1 = [img_Loc1'; ones(1, pt_Count)];
    
   
    prime_Homog = [];
    
    for i=1:N
       inlier_count_Thresh = 0;
     
       H = calcH(img_Loc1, img_Loc2);
       
       temp = H * homog_ImgLoc1;
       temp = [temp(1, :) ./ temp(3, :); temp(2, :) ./ temp(3, :)];
       
       for ndx =1:n
       
       diff = sqrt(sum((temp - img_Loc2').^2, 1));
        if (diff <= inlier_Thresh)
            inlier_count_Thresh = inlier_count_Thresh +1;
        end
       end
       if (inlier_count_Thresh > max)
           max = inlier_count_Thresh;
          
           prime_Homog = H;
       end
    end
    
    H = prime_Homog;
    
   % if prime_InlinerFrac < inlier_Count_Thresh 
    %    fprintf( ...
     %       sprintf('RANSAC can only match %f, while threshold is %f\n', ...
      %      prime_InlinerFrac,  inlier_Count_Thresh));
    
    % re-estimate
    %if isempty(prime_Homog)
     %   H = [];
    %else
     %   H = calcH(img_Loc1(in_Liers, :), img_Loc2(in_Liers, :));
    %end
