function pair = match2viewSIFT(frames, image_i, image_j,FASTCONFIG)

histeq=1;
SURF=0;MaxPoints=50;

 if FASTCONFIG==1
    ds=2;
    image_i=imresize(image_i,1/ds);
    image_j=imresize(image_j,1/ds);
    
 else
     ds=1;
 end

if histeq==1
    addpath(genpath('C:\Users\boschm1\Documents\MATLAB\opensurf\'))
         % Scale image to between 0 and 1
         config.Preprocess.NumTiles = [10 10];
        config.Preprocess.ClipLimit = 0.015;
        config.Preprocess.NBins = 256;
        config.Preprocess.Distribution = 'rayleigh';
        image_i = image_i - min(image_i(:));
        image_i = image_i/max(image_i(:));
        
        % Perform adaptive histogram equalization
        image_i = adapthisteq(image_i,'NumTiles',config.Preprocess.NumTiles,...
            'ClipLimit',config.Preprocess.ClipLimit,...
            'NBins',config.Preprocess.NBins,...
            'Distribution',config.Preprocess.Distribution);
        
        % Scale image to a uint8 RBG image for later processing
        image_i = (image_i*255);
        
        
         % Scale image to between 0 and 1
        image_j = image_j - min(image_j(:));
        image_j = image_j/max(image_j(:));
        
        % Perform adaptive histogram equalization
        image_j = adapthisteq(image_j,'NumTiles',config.Preprocess.NumTiles,...
            'ClipLimit',config.Preprocess.ClipLimit,...
            'NBins',config.Preprocess.NBins,...
            'Distribution',config.Preprocess.Distribution);
        
        % Scale image to a uint8 RBG image for later processing
        image_j = (image_j*255);
end


if SURF==1
    Ii1=image_i;Ii2=image_j;
    I1(:,:,1)=double(Ii1./max(Ii1(:)));
  I1(:,:,2)=double(Ii1./max(Ii1(:)));
  I1(:,:,3)=double(Ii1./max(Ii1(:)));
  I2(:,:,1)=double(imresize(Ii2,size(Ii1))./max(Ii2(:)));
  I2(:,:,2)=double(imresize(Ii2,size(Ii1))./max(Ii2(:)));
  I2(:,:,3)=double(imresize(Ii2,size(Ii1))./max(Ii2(:)));
  
% Get the Key Points
%   Options.upright=true;
%   Options.tresh=0.000001;
  Options=struct('tresh',0.000001,'octaves',5,'init_sample',2,'upright',true,'extended',false,'verbose',false);
  Ipts1=OpenSurf(I1,Options);
  Ipts2=OpenSurf(I2,Options);
% Put the landmark descriptors in a matrix
  D1 = reshape([Ipts1.descriptor],64,[]); 
  D2 = reshape([Ipts2.descriptor],64,[]); 
% Find the best matches
  err=zeros(1,length(Ipts1));
  cor1=1:length(Ipts1); 
  cor2=zeros(1,length(Ipts1));
  for i=1:length(Ipts1),
      distance=sum((D2-repmat(D1(:,i),[1 length(Ipts2)])).^2,1);
      [err(i),cor2(i)]=min(distance);
  end
% Sort matches on vector distance
  [err, ind]=sort(err); 
  cor1=cor1(ind); 
  cor2=cor2(ind);  
  if size(image_i,2)>2280
      for ij=1:MaxPoints
        SIFTloc_i(1,ij)=2*Ipts1(cor1(ij)).x;
        SIFTloc_i(2,ij)=2*Ipts1(cor1(ij)).y;
        SIFTloc_j(1,ij)=2*Ipts2(cor2(ij)).x;
        SIFTloc_j(2,ij)=2*Ipts2(cor2(ij)).y;
      end
  else
      for ij=1:MaxPoints
        SIFTloc_i(1,ij)=Ipts1(cor1(ij)).x;
        SIFTloc_i(2,ij)=Ipts1(cor1(ij)).y;
        SIFTloc_j(1,ij)=Ipts2(cor2(ij)).x;
        SIFTloc_j(2,ij)=Ipts2(cor2(ij)).y;
      end
  end
  
  pair.matches = [SIFTloc_i;SIFTloc_j];
  
  size(SIFTloc_i)
  

else



     [SIFTloc_i,SIFTdes_i] = vl_sift(image_i) ;
     [SIFTloc_j,SIFTdes_j] = vl_sift(image_j) ;
    
   
     [matches, scores] = vl_ubcmatch(SIFTdes_i, SIFTdes_j) ;
     
     
     SIFTloc_i = ds*SIFTloc_i([1 2],matches(1,:));
     SIFTloc_j = ds*SIFTloc_j([1 2],matches(2,:));
     
     pair.matches = [SIFTloc_i;SIFTloc_j];
end


