Tidy mutex and contour limit

Moved the mutex variables to the instance.
Added a limit of 4000 contours as more contours than this caused an
iPhone 5 to take 8-20 seconds to process one frame.