cvCopyHist bugfix and cleanup

Fix subtle bug when src & dst agree on sparsity but have different dimensions
Remove unused var "total"
Declare vars as locally as possible