# Revision history [back]

I got stuck with this too and it took me almost 3-4 hours to figure this out. When you apply knn match , make sure that number of features in both test and query image is greater than or equal tonumber of nearest neighbours in knn match.
say for example, we have this code:

Mat img1,img2,desc1,desc2;
vector<KeyPoint> kpt1,kpt2;

FAST(img1,kpt1,30,true) ;
FAST(img2,kpt1,30,true) ;

SurfDescriptorExtractor sfdesc1,sfdesc2;
sfdesc1.compute(img1,kpt1,desc1);
sfdesc2.compute(img2,kpt2,desc2);

FlannBasedMatcher matcher;
vector< vector<DMatch> > matches1,matches2;
matcher.knnMatch(desc1,desc2,matches1,2);


this code will return exception as in the post, just modify the code as show below:

if(kpt1.size()>=2 && kpt2.size()>=2)
matcher.knnMatch(desc1,desc2,matches1,2);


this method worked for me ..!!