Hey,
Please format your code: select all the code you pasted and then click on the icon </>
.
You can edit your post by clicking the small pen on the bottom right of your post.
Also try to transform your problem into a small example that anyone can try and understand completely, right now we need to understand all of your code to help you.
For you problem I think you are messing up the currentSmallest thingy.
You have actually two things:
- the smallest distance that you found
- and the pixel that correspond to that smallest distance
You need to keep track of both of them.