Min() function crashing Photon

I have this code:

int bk0=(beaks[0]+1)/2;
int bk1=(beaks[1]+1)/2;
int bk2=(beaks[2]+1)/2; // beaks are integers
minCount = min(bk0, bk1);
minCount = min(minCount, bk2);

This compiles perfectly (obviously!!). But the Photon hangs every time it executes these statements. It has taken me the entire day to find that min() function is causing this. Since replacing with if else statements, it is working perfectly!!

I copied the function to a new project in the loop() function. There it works!!

Any idea why this should not work in a function??!! Can somebody replicate the error?

It seems there is something else wrong with the code. Please ignore this post.