This the MATLAB code base the following journal paper :
A fast approximate nearest neighbor search algorithm in the hamming space Mani Malek Esmaeili, et. al - in IEEE transactions of Pattern Analysis and Machine Intelligence, 2012
Note: Minimal commenting has been done, you need to read the paper to understand the code! Sorry!