Equivalent of matchFeatures() Matlab in OpenCV (C++)

Hi everyone! I’m working on my Visual Odometry project. I’m using SURF detector and BRUTEFORCE matching in this way:

//-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors`
Ptr<SURF> detector = SURF::create( minHessian );`
vector<KeyPoint> keypoints1, keypoints2;`
Mat descriptors1, descriptors2;`
detector->detectAndCompute( img1, noArray(), keypoints1, descriptors1 );`
detector->detectAndCompute( img2, noArray(), keypoints2, descriptors2 );`
//-- Step 2: Matching descriptor vectors with a brute force matcher`
// Since SURF is a floating-point descriptor NORM_L2 is used`
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);`
vector< DMatch > matches;`
matcher->match( descriptors1, descriptors2, matches);`

But my result is different from matchFeatures() of MATLAB. In particular, the size of matches is equal to the size of keypoints1, meanwhile in MATLAB, it’s a different size.

After, for matching and converting Keypoints in v ector<Point2f> i’m using this loop:

// Convert keypoints into Point2f (Solo i KP matchati)
vector<Point2f> keypoints1_conv, keypoints2_conv;
for (vector<DMatch>::const_iterator it= kp_match.match.begin(); it!= kp_match.match.end(); ++it)
// Get the position of keypoints1
keypoints1_conv.push_back(kp_match.Kpoints1[it->queryIdx].pt); //query per keypoints1
// Get the position of keypoints2
keypoints2_conv.push_back(kp_match.Kpoints2[it->trainIdx].pt); //train per keypoints2

I tried also with knnMatch and radiusMatch, but with similar results.

I found solution on this tutorial.