function match(image1, image2) {
const matcher = new cv.BFMatcher(cv.NORM_HAMMING, true);
const matches = new cv.DMatchVector();
matcher.match(image1.descriptors, image2.descriptors, matches);
image1.matchedKeypoints = [];
image2.matchedKeypoints = [];
for (let i = 0; i < matches.size(); ++i) {
const match = matches.get(i);
const query = image1.keypoints.get(match.queryIdx).pt;
image1.matchedKeypoints.push(query.x, query.y);
const train = image2.keypoints.get(match.trainIdx).pt;
image2.matchedKeypoints.push(train.x, train.y);
}
image1.matchedKeypoints = cv.matFromArray(matches.size(), 2, cv.CV_32F, image1.matchedKeypoints);
image2.matchedKeypoints = cv.matFromArray(matches.size(), 2, cv.CV_32F, image2.matchedKeypoints);
}