Example that seems to work, using Cinder:
ci::Matrix44f derivedRotMatrix = LeapMotion::toMatrix44f(bone.basis().rigidInverse());
float w = sqrtf(1.0 + derivedRotMatrix.at(0,0) + derivedRotMatrix.at(1,1) + derivedRotMatrix.at(2,2)) / 2.0;
double w4 = (4.0 * w);
float x = (derivedRotMatrix.at(2,1) - derivedRotMatrix.at(1,2)) / w4 ;
float y = (derivedRotMatrix.at(0,2) - derivedRotMatrix.at(2,0)) / w4 ;
float z = (derivedRotMatrix.at(1,0) - derivedRotMatrix.at(0,1)) / w4 ;
ci::Quatf rotation(w, x, y , z);
modified from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/