nrf51822 BLE beacon not always discoverable - how to choose the correct flag?
so the beacon went out from scanning app after some minute


Nope. This only happens if the beacon stops advertising altogether - which they tend to do in order to save power. 

This is also why you usually want to program those NRF5x chips yourself - so you can customize timouts and other important stuff.