test knnMatch edge case with keypoints < knn

Test for bug #3172 (http://code.opencv.org/issues/3172)
BFMatcher::knnMatch can return garbage when one of its train images has fewer than k keypoints. (The test failures might not be deterministic; I think the bug causes BFMatcher to read from uninitialized memory.)

I'm also willing to contribute a fix for the bug, not just a test. But I'm still waiting for the OpenCV community to provide advice whether it is more sensible to fix the bug in BFMatcher::knnMatchImpl, or in cv::batchDistance. (I had proposed the latter in rejected pull request 2770.)