OpenCV: Problem at creating a Skeleton of Lines
You are actually drawing the skeleton of the background (brighter region).  

change 

cv::threshold(image, image, threshold, 255, cv::THRESH_BINARY);


in your codes to 

cv::threshold(image, image, threshold, 255, cv::THRESH_BINARY_INV); 


You should be able to get the right skeleton.