improved svm_thres function