is there a fast way to find that the uploaded image is similar to an image that exists in a specific folder that contains thousand images?

from cv2 import cv2
import numpy as np
import os
import io
import flask
from flask import Flask,request, jsonify

app = flask.Flask(__name__)
app.config(“DEBUG”) = True
path = ‘images’

@app.route(‘/check’, methods=(‘POST’))
def api_id():
f = request.files(‘imagefile’).read()
npimg = np.frombuffer(f,np.uint8)
captured = cv2.imdecode(npimg,cv2.IMREAD_COLOR)
myList = os.listdir(path)
print(‘Total Classes Detected’, len(myList))
for cl in myList:
image_to_compare = cv2.imread(f'{path}/{cl}’,0)

# Initiate BRISK descriptor
BRISK = cv2.BRISK_create()

# Find the keypoints and compute the descriptors for input and training-set image
keypoints1, descriptors1 = BRISK.detectAndCompute(image_to_compare, None)
keypoints2, descriptors2 = BRISK.detectAndCompute(captured, None)

# create BFMatcher object
BFMatcher = cv2.BFMatcher(normType = cv2.NORM_HAMMING,
crossCheck = True)

# Matching descriptor vectors using Brute Force Matcher
matches = BFMatcher.match(queryDescriptors = descriptors1,
trainDescriptors = descriptors2)

# Sort them in the order of their distance
matches = sorted(matches, key = lambda x: x.distance)

number_keypoints = 0
if len(keypoints1) = 50 :
r1 = {“ID”: os.path.splitext(cl)(0) ,”SIMILAR”:”true” }
return jsonify(r1)

r2 = {“SIMILAR”: “false”}
return jsonify(r2)

app.run()