title: Drawing matches from Nearest Neighbour Distance Ratio
body: <p>In openCV I have adapted this tutorial code in my application </p>
  
  <p><a href="http://docs.opencv.org/2.4.2/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography" rel="nofollow">http://docs.opencv.org/2.4.2/doc/tutorials/features2d/feature_homography/feature_homography.html#feature-homography</a> </p>
  
  <p>I have been trying to prune the matches using the Nearest Neighbour Distance Ratio to only draw matches above a certain threshold value.</p>
  
  <pre><code>  double ratio = 0.9;
    std::vector&lt; vector&lt;DMatch &gt; &gt; nnMatches;
    std::vector&lt; DMatch &gt; good_NNmatches;
    matcher.knnMatch(descriptors_scene, descriptors_object, nnMatches, 2 );
  
    for(int k = 0; k &lt; nnMatches.size(); k++)
    {
        if(nnMatches[k][0].distance / nnMatches[k][1].distance &gt; ratio)
        {
            good_NNmatches.push_back(nnMatches[k][0]);
        }
    }
  </code></pre>
  
  <p>I am then trying to draw the matches in good_NNmatches using the same method demonstrated in the tutorial but I get the following error:</p>
  
  <pre><code>OpenCV Error: Assertion failed (i1 &gt;= 0 &amp;&amp; i1 &lt; static_cast&lt;int&gt;(keypoints1.size())) in     drawMatches, file /Users/cgray/Downloads/opencv-2.4.6/modules/features2d/src/draw.cpp, line 207
  libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /Users/cgray/Downloads/opencv-2.4.6/modules/features2d/src/draw.cpp:207: error: (-215) i1 &gt;= 0 &amp;&amp; i1 &lt; static_cast&lt;int&gt;(keypoints1.size()) in function drawMatches
  </code></pre>
  
  <p>When trying to call drawMatches using good_nnMatches instead of good_matches as described in the tutorial.</p>
  
  <pre><code>drawMatches( roiImg, keypoints_object, compare, keypoints_scene,
                       good_NNmatches, img_matches, Scalar::all(-1), Scalar::all(-1),
                       vector&lt;char&gt;(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
  </code></pre>