For the first few iterations it worked perfectly but later on it throw out the same error not sure what exactly is happening..
im1_new=cv2.cvtColor(im1, cv2.COLOR_BGR2RGB)
im2_new=cv2.cvtColor(im2, cv2.COLOR_BGR2RGB)
sift=cv2.xfeatures2d.SIFT_create()
kp1,des1=sift.detectAndCompute(im1_new,None)
kp2,des2=sift.detectAndCompute(im2_new,None)
matcher = cv2.BFMatcher()
matches=matcher.knnMatch(des1,des2,k=2)