Code:
BinaryImage *thresholdImage = image->ThresholdHSV(threshold);
It looks like you're trying to create a pointer and store something in what it points to at the same time. That will write over an undefined area in memory. Or maybe you're just setting it to something that won't fit in a pointer, and thus overwriting memory that way?
Don't do that.
Instead, declare the pointer, then allocate memory and set the pointer to point to the newly allocated memory. Only after that's done can you dereference the pointer. Alternatively, you might want to create
thresholdImage as a
BinaryImage instead of a pointer to one.