Have a look at the code of http://cvlab.epfl.ch/research/detect/brief in utils.cpp.