I have this pattern in the first image which I want to find in the second image. However the two images are totally different so I just need to find the closest set of indices where these two images match. So how to go about it? Are there existing algorithms doing the same?
The simplest algorithm that is mathematically tractable is the matched filter. It is designed to find both the presence of (yes/no) and the location on a "target" in a "scene". However, the matched filter does not work incredibly well if there are rotations or scaling of the "target" in the scene relative to the target's image.
Assuming the "target" is in the "scene", the matched filter gives incredibly good results if the only thing corrupting the "scene" is noise. To deal with rotations, one can try "matching" rotated and scaled versions of the target image in the scene. There are many variations of the matched filter for many different signal processing applications, but in image processing, it is sometimes called "cross-correlation".
The modern approach to this "pattern recognition" problem is machine learning, using Neural Networks or Support Vector Machines. These concepts are much more difficult to learn.
MATLAB has a lot of useful tools for accomplishing these tasks, and their online documentation has a lot of examples.
A variation of the matched filter that is more robust to different types of noise existing in the same image is the Normalized Cross-Correlation (also a function in MATLAB, normxcorr2 as opposed to xcorr2, which is a classic matched filter). Theoretically, it is described here by Lewis...
But, although norm x-corr can deal with different types of noise, it is still useless under scaling and rotation, unless one repeats the function over and over for different combinations of rotations and scales. Even then, it can be difficult to find the target, unless you get very granular with the rotations and scales.
Hope this helps. I can describe more of these methods in detail if needed.
Note that although the theory of the matched filter might seem extreme, the implementation is very easy, especially if you just use xcorr2 or normxcorr2 in MATLAB.