Create threshold optimization step between detection and scoring

Docstring explaining what this function does?