Fix for Bug #3085

http://code.opencv.org/issues/3085

`weights` array is only allocated for `l_count+1` elements,
but then `weights[l_count+1]` element is accessed.