This article gives a brief introduction about how to calculate the SIFT/SURF descriptors with Bag-of-Words(features) model:
http://www.codeproject.com/Articles/619039/Bag-of-Features-Descriptor-on-SIFT-Features-with-O
http://www.codeproject.com/Tips/656906/Bag-of-Features-Descriptor-on-SURF-and-ORB-Feature